apiVersion: v1
kind: Service
metadata:
  name: openpitrix-minio
  namespace: ${NAMESPACE}
  labels:
    app: openpitrix
    tier: minio
    version: ${VERSION}
spec:
  selector:
    app: openpitrix
    tier: minio
  ports:
  - name: tcp
    protocol: TCP
    port: 9000
    targetPort: 9000

{% if persistence.enable is defined and persistence.enable == true %} 
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: openpitrix-minio-pvc
  namespace: ${NAMESPACE}
  labels:
    app: openpitrix
    tier: minio
spec:
  accessModes:
    - ReadWriteOnce
{% if persistence.storageClass is defined and persistence.storageClass != None %} 
  storageClassName: {{ persistence.storageClass }}
{% endif %}
  resources:
    requests:
      storage: 20Gi
{% endif %}

---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: openpitrix-minio-deployment
  namespace: ${NAMESPACE}
  labels:
    app: openpitrix
    tier: minio
    version: ${VERSION}
spec:
  selector:
    matchLabels:
      app: openpitrix
      tier: minio
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: openpitrix
        tier: minio
        version: ${VERSION}
    spec:
      containers:
      - name: openpitrix-minio
        image: {{ minio_repo }}:{{ minio_tag }}
        imagePullPolicy: IfNotPresent
        lifecycle:
          postStart:
            exec:
              command: ["sh", "-c", "mkdir -p /data/openpitrix-internal-repo/vmbased /data/openpitrix-internal-repo/helm"]
        args:
          - server
          - /data
        env:
        - name: MINIO_ACCESS_KEY
          value: "openpitrixminioaccesskey"
        - name: MINIO_SECRET_KEY
          value: "openpitrixminiosecretkey"
        ports:
        - containerPort: 9000
          name: minio
        volumeMounts:
        - name: minio-persistent-storage
          mountPath: /data
      volumes:
      - name: minio-persistent-storage
{% if persistence.enable is defined and persistence.enable == true %}  
        persistentVolumeClaim:
          claimName: openpitrix-minio-pvc
{% else %} 
        hostPath:
          path: /var/lib/kubesphere/minio-data
          type: DirectoryOrCreate
{% endif %}